<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="../assets/js/vue.js"></script>
    <title>Document</title>
</head>
<body>
    <h1> 第8节：Component 标签</h1>
    <hr>
    <div id="app">
        <h2>conponent 标签可以根据data 中的值来更换我们的组件</h2>
       <component v-bind:is='who'></component> 
       <h2>点击切换组件</h2>
       <button type="button" @click="changeComponent">changeComponent</button>
    </div>
</body>
<script>
    var componentA = {
        template:`<div style="color:red">我是componentA</div>`,
    };
    var componentB = {
        template:`<div style="color:blue">我是componentB</div>`,
    };
    var componentC = {
        template:`<div style="color:pink">我是componentC</div>`
    }
    var app =  new Vue({
        el:"#app",
        data:{
            "who":componentA,
        },
        methods:{
            // 我们的方法处理都在此处
            changeComponent:function(){
                if(this.who == 'componentA'){
                    this.who = 'componentB'
                }else if(this.who == "componentB"){
                    this.who = 'componentC';
                }else{
                    this.who = 'componentA'
                }   
            },
        },
        computed:{  
            // 数据有需要单独处理的写在此处，vue不允许直接操作原数组和原对象。
        },
        components:{
           "componentA":componentA,
           "componentB":componentB,
           "componentC":componentC
        }
        
    });
</script>
</html>